package com.lb.tools.lbtools.tools;

public class CountWrodRepeatTimeUtil {

	public static void main(String[] args) throws Exception {
		int count = count(
		"it is a good day i am very like it how are you do you like it","it");
		System.out.println(count);

	}

	/**
	 * 计算字符出现的次数
	 * 
	 * @param text
	 *            文本字符串
	 * @param target
	 *            需要找个数的字符
	 * @return
	 */
	public static int count(String text, String target) {
		int count = 0;
		int index = 0;
		while (true) {
			index = text.indexOf(target, index);
			if (index == -1) {
				break;
			}
			index = index + target.length();
			if (index >= 0) {
				count++;
			} else {
				break;
			}
		}
		return count;
	}

}
